package com.baicaoyuan.web.repository;


import com.baicaoyuan.web.model.JzzProfitInputDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 功能描述：
 *
 * @author 罗富祥
 * 创建时间： 2018/1/4
 * 版权：
 */
@Repository
public interface JzzProfitInputRepository extends JpaRepository<JzzProfitInputDO, Long> {

    @Query(value = "SELECT DISTINCT(period_no) from t_jzz_profit_input where status = ?1", nativeQuery = true)
    List<String> getDistinctPeriodNo(Integer status);

    @Transactional
    @Modifying
    @Query(value = "update t_jzz_profit_input set status = ?2 where period_no in (?1) and status = 0", nativeQuery = true)
    Integer checkProfit(List<String> periodNos, Integer status);


    @Transactional
    @Modifying
    @Query(value = "update t_jzz_profit_input set status = ?2 where period_no in (?1) ", nativeQuery = true)
    Integer revertProfit(List<String> periodNos, Integer status);

    @Transactional
    @Modifying
    @Query(value = "update t_jzz_profit_input set status = ?2 where id = ?1", nativeQuery = true)
    Integer updateStatus(Long id, Integer status);

    Integer countAllByStatusAndPeriodNoLikeAndSerialNumberLike(Integer status, String periodNo, String serialNumber);

    Integer countAllByPeriodNoLikeAndSerialNumberLike(String periodNo, String serialNumber);

    @Query(value = "select * from t_jzz_profit_input where status = ?1 and period_no like ?2 and serial_number like ?3 ORDER BY id DESC Limit ?4,?5", nativeQuery = true)
    List<JzzProfitInputDO> queryJzzProfitInput(Integer status, String periodNo, String serialNumber, Integer pageNo, Integer pageSize);

    @Query(value = "select * from t_jzz_profit_input where period_no like ?1 and serial_number like ?2 ORDER BY id DESC Limit ?3,?4", nativeQuery = true)
    List<JzzProfitInputDO> queryJzzProfitInput(String periodNo, String serialNumber, Integer pageNo, Integer pageSize);

    @Query(value = "select * from t_jzz_profit_input where status = ?1", nativeQuery = true)
    List<JzzProfitInputDO> queryJzzProfitInput(Integer status);
}
